package gdconf

import (
	"server_cluster/common/logger"
)

// 战斗配置表

type BattleConfig struct {
	BattleId      int32    `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 战斗id
	MonsterIdList IntArray `csv:"Monster,omitempty"`                         // 怪物id列表
}

func (b *BattleConfig) TableName() string {
	return "config_battle_logic"
}

func (g *GameDataConfig) saveBattleConfig() {
	saveTableToDb[BattleConfig](g.Db, readTable[BattleConfig](g.CsvPathPrefix+"Battle.csv"))
}

func (g *GameDataConfig) loadBattleConfig() {
	g.GameDataMaps.BattleConfigMap = make(map[int32]*BattleConfig)
	for _, battleConfig := range loadTableFromDb[BattleConfig](g.Db) {
		g.GameDataMaps.BattleConfigMap[battleConfig.BattleId] = battleConfig
	}
	logger.Info("BattleConfig Count: %v", len(g.GameDataMaps.BattleConfigMap))
}

func GetBattleConfig(battleId int32) *BattleConfig {
	value, exist := CONF.GameDataMaps.BattleConfigMap[battleId]
	if !exist {
		logger.Error("[ConfigNotFound] BattleConfig, battleId: %v", battleId)
		return nil
	}
	return value
}

func GetBattleConfigMap() map[int32]*BattleConfig {
	return CONF.GameDataMaps.BattleConfigMap
}
